class SparseTable:
    def __init__(self, n):
        self.n = n
        inf = float('inf')
        self.tree = [inf] * (2 * n)

    def update(self, pos, val):
        pos += self.n
        self.tree[pos] = min(val,self.tree[pos])
        while pos:
            l = r = pos
            if pos % 2 == 0:
                r = pos + 1
            else:
                l = pos - 1
            self.tree[pos // 2] = min(self.tree[l], self.tree[r])
            pos //= 2

    def range(self, l, r):
        l += self.n
        r += self.n
        ans = -1
        while l <= r:
            if l & 1:
                ans = min(ans, self.tree[l])
                l += 1
            if (r & 1) == 0:
                ans = min(ans, self.tree[r])
                r -= 1
            l //= 2
            r //= 2
        return ans